package com.evan.review.viewpager;

import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.evan.review.R;

/**
 * 简单页面Fragment
 * 用于在ViewPager中展示不同颜色的页面
 */
public class SimplePageFragment extends Fragment {
    
    private static final String TAG = "SimplePageFragment";
    private static final String ARG_PAGE_NUMBER = "page_number";
    private static final String ARG_BACKGROUND_COLOR = "background_color";
    
    private int pageNumber;
    private int backgroundColor;
    
    /**
     * 创建SimplePageFragment的新实例
     * @param pageNumber 页面编号
     * @param backgroundColor 背景颜色
     * @return 新的SimplePageFragment实例
     */
    public static SimplePageFragment newInstance(int pageNumber, int backgroundColor) {
        SimplePageFragment fragment = new SimplePageFragment();
        Bundle args = new Bundle();
        args.putInt(ARG_PAGE_NUMBER, pageNumber);
        args.putInt(ARG_BACKGROUND_COLOR, backgroundColor);
        fragment.setArguments(args);
        Log.d(TAG, "newInstance: 页面编号=" + pageNumber);
        return fragment;
    }
    
    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            pageNumber = getArguments().getInt(ARG_PAGE_NUMBER);
            backgroundColor = getArguments().getInt(ARG_BACKGROUND_COLOR);
        }
        Log.d(TAG, "onCreate: 页面编号=" + pageNumber);
    }
    
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        Log.d(TAG, "onCreateView: 页面编号=" + pageNumber);
        View view = inflater.inflate(R.layout.fragment_simple_page, container, false);
        view.setBackgroundColor(backgroundColor);
        
        TextView tvPageNumber = view.findViewById(R.id.tv_page_number);
        tvPageNumber.setText("页面 " + pageNumber);
        
        return view;
    }
    
    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        Log.d(TAG, "onViewCreated: 页面编号=" + pageNumber);
    }
    
    @Override
    public void onAttach(@NonNull Context context) {
        super.onAttach(context);
        Log.d(TAG, "onAttach: 页面编号=" + pageNumber);
    }
    
    @Override
    public void onDetach() {
        super.onDetach();
        Log.d(TAG, "onDetach: 页面编号=" + pageNumber);
    }
    
    @Override
    public void onStart() {
        super.onStart();
        Log.d(TAG, "onStart: 页面编号=" + pageNumber);
    }
    
    @Override
    public void onResume() {
        super.onResume();
        Log.d(TAG, "onResume: 页面编号=" + pageNumber);
    }
    
    @Override
    public void onPause() {
        super.onPause();
        Log.d(TAG, "onPause: 页面编号=" + pageNumber);
    }
    
    @Override
    public void onStop() {
        super.onStop();
        Log.d(TAG, "onStop: 页面编号=" + pageNumber);
    }
    
    @Override
    public void onDestroyView() {
        super.onDestroyView();
        Log.d(TAG, "onDestroyView: 页面编号=" + pageNumber);
    }
    
    @Override
    public void onDestroy() {
        super.onDestroy();
        Log.d(TAG, "onDestroy: 页面编号=" + pageNumber);
    }
    
    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        Log.d(TAG, "setUserVisibleHint: 页面编号=" + pageNumber + ", 对用户可见=" + isVisibleToUser);
    }
} 